package movee.websocket.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@Slf4j
@RestController
@RequestMapping("/message")
public class MessagePushController {

    @RequestMapping("/push/{cid}")
    public String pushToWeb(@PathVariable String cid,
                            @RequestParam String message) {
        try {
            WebSocketServer.sendInfo(message,cid);
        } catch (IOException e) {
            log.error("{}",e.getMessage());
            return "ERROR " + cid + " : send message is error";
        }
        return "SUCCESS " + cid + " : send message is success";
    }


}
